package com.mfhcd.facepay.network.api;

import android.content.Context;

import com.mfhcd.facepay.model.BaseRequestModel;
import com.mfhcd.facepay.model.BaseResponseModel;
import com.mfhcd.facepay.model.RequestModel;
import com.mfhcd.facepay.model.ResponseModel;
import com.mfhcd.facepay.network.BaseNetworkRequest;
import com.mfhcd.facepay.network.NetworkUtils;
import com.mfhcd.facepay.network.callback.CallBack;

/**
 * Author：石强
 * E-Mail: shiqiang@mfhcd.com
 * Date：2019-09-06
 * 版权所有 © 现代金融控股（成都）有限公司
 */
public class NetworkRequest extends BaseNetworkRequest<NetworkRequest> {
    private static NetworkRequest mInstance;
    private NetworkService mNetworkService;

    public NetworkRequest() {
        mNetworkService = NetworkUtils.getInstance().create(NetworkService.class);
    }

    public static NetworkRequest getInstance() {
        if (mInstance == null) {
            synchronized (NetworkRequest.class) {
                if (mInstance == null) {
                    mInstance = new NetworkRequest();
                }
            }
        }
        return mInstance;
    }


    @Override
    public NetworkRequest builder(Context context) {
        this.mContext = context;
        return this;
    }

    public void test(BaseRequestModel requestModel, CallBack<BaseResponseModel<ResponseModel.TestResp>> callback) {
        NetworkUtils.getInstance().setSubscribe(mContext, mNetworkService.test(requestModel, requestModel.constructUrl()), callback);
    }

    public void faceRouter(RequestModel.TrxDataReq requestModel, CallBack<ResponseModel.TrxDataResp> callBack) {
        NetworkUtils.getInstance().setSubscribe(mContext, mNetworkService.faceRouter(requestModel, requestModel.constructUrl()), callBack);
    }

    public void doTransaction(RequestModel.TransReq requestModel, CallBack<ResponseModel.TransResp> callBack) {
        NetworkUtils.getInstance().setSubscribe(mContext, mNetworkService.doTransaction(requestModel, requestModel.constructUrl()), callBack);
    }
}
